package cn.itsource.basic.controller;

import cn.itsource.utils.AjaxResult;
import cn.itsource.utils.FastdfsUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/fastDfs")
public class FastDFSController {

    @RequestMapping("/upload")
    @ResponseBody
    public AjaxResult upload(MultipartFile file){
        // 获取文件名
        String filename = file.getOriginalFilename();
        // 截取后缀.后面不包括.
        String fileSuffix = filename.substring(filename.lastIndexOf(".") + 1);

        try {
            String path = FastdfsUtil.upload(file.getBytes(), fileSuffix);
            return AjaxResult.me().setResultObj(path);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;


    }

}
